Show the time of last change in the file chooser, for files modified today
authorEmmanuele Bassi <ebassi@gnome.org>
Tue, 26 Jun 2007 20:37:44 +0000 (20:37 +0000)
committerEmmanuele Bassi <ebassi@src.gnome.org>
Tue, 26 Jun 2007 20:37:44 +0000 (20:37 +0000)
2007-06-26  Emmanuele Bassi  <ebassi@gnome.org>

* gtk/gtkfilechooserdefault.c (list_mtime_data_func): Show
the time of last change in the file chooser, for files
modified today or yesterday. (#324543)

* configure.in: Check for localtime_r().

svn path=/trunk/; revision=18248

ChangeLog
configure.in
gtk/gtkfilechooserdefault.c

index 590da07f555d5328341b069e3e63c1794cb4a149..c10eb4d1ecdfb189a30cb4978056db88e7b68af6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-06-26  Emmanuele Bassi  <ebassi@gnome.org>
+
+       * gtk/gtkfilechooserdefault.c (list_mtime_data_func): Show
+       the time of last change in the file chooser, for files
+       modified today or yesterday. (#324543)
+
+       * configure.in: Check for localtime_r().
+
 2007-06-26  Cody Russell  <bratsche@gnome.org>
 
        * modules/engines/ms-windows/xp_theme.[ch]
index 9bfa3feb0d6c9e3adbef13c79a0c79919151ff5c..d03f9dfb67de8c6d7d80ee9b1958710604fabc10 100644 (file)
@@ -410,6 +410,7 @@ fi
 AC_SUBST(REBUILD)
 
 AC_CHECK_FUNCS(lstat mkstemp flockfile getc_unlocked)
+AC_CHECK_FUNCS(localtime_r)
 
 # _NL_TIME_FIRST_WEEKDAY is an enum and not a define
 AC_MSG_CHECKING([for _NL_TIME_FIRST_WEEKDAY])
index 63bdaf2fdd5f3c9063826a42d40b4973fc901b23..0baec772975fa36292c8edc8f105c8c4b02c1ac3 100644 (file)
@@ -10884,9 +10884,7 @@ list_mtime_data_func (GtkTreeViewColumn *tree_column,
 {
   GtkFileChooserDefault *impl;
   GtkFileTime time_mtime;
-  GDate mtime, now;
-  int days_diff;
-  char buf[256];
+  gchar *date_str = NULL;
   gboolean sensitive = TRUE;
 
   impl = data;
@@ -10954,39 +10952,65 @@ list_mtime_data_func (GtkTreeViewColumn *tree_column,
        sensitive = gtk_file_info_get_is_folder (info);
     }
 
-  if (time_mtime == 0)
-    strcpy (buf, _("Unknown"));
+  if (G_UNLIKELY (time_mtime == 0))
+    date_str = g_strdup (_("Unknown"));
   else
     {
+      GDate mtime, now;
+      gint days_diff;
+      struct tm tm_mtime;
       time_t time_now;
+      const gchar *format;
+      gchar buf[256];
+
+#ifdef HAVE_LOCALTIME_R
+      localtime_r ((time_t *) &time_mtime, &tm_mtime);
+#else
+      {
+        struct tm *ptm = localtime ((time_t *) &time_mtime);
+
+        if (!ptm)
+          {
+            date_str = g_strdup (_("Unknown"));
+            g_warning ("ptm != NULL failed");
+            goto done;
+          }
+        else
+          memcpy ((void *) &tm, (void *) ptm, sizeof (struct tm));
+      }
+#endif /* HAVE_LOCALTIME_R */
+
       g_date_set_time_t (&mtime, time_mtime);
       time_now = time (NULL);
       g_date_set_time_t (&now, time_now);
 
       days_diff = g_date_get_julian (&now) - g_date_get_julian (&mtime);
 
+      /* Translators: %H means "hours" and %M means "minutes" */
       if (days_diff == 0)
-       strcpy (buf, _("Today"));
+        format = _("Today at %H:%M");
       else if (days_diff == 1)
-       strcpy (buf, _("Yesterday"));
+       format = _("Yesterday at %H:%M");
       else
        {
-         char *format;
-
          if (days_diff > 1 && days_diff < 7)
            format = "%A"; /* Days from last week */
          else
            format = "%x"; /* Any other date */
-
-         if (g_date_strftime (buf, sizeof (buf), format, &mtime) == 0)
-           strcpy (buf, _("Unknown"));
        }
+
+      if (strftime (buf, sizeof (buf), format, &tm_mtime) != 0)
+        date_str = g_strdup (buf);
+      else
+       date_str = g_strdup (_("Unknown"));
     }
 
+done:
   g_object_set (cell,
-               "text", buf,
+               "text", date_str,
                "sensitive", sensitive,
                NULL);
+  g_free (date_str);
 }
 
 GtkWidget *